<template>
  <div class="app-container">
    <el-card class="contentBox">
      <h1 class="title">使用记录</h1>
      <p class="subTitle">查看您的视频生成历史记录</p>
      <el-card class="kill-margin">
        <template #header>
          <div class="card-header">
            <span>历史记录</span>
            <el-tag type="primary" style="margin-left: 15px"
              >共 {{ total }} 条记录</el-tag
            >
          </div>
        </template>
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="描述" prop="des">
            <el-input v-model="queryParams.des" />
          </el-form-item>
          <el-form-item label="任务类型" prop="taskType">
            <el-radio-group
              v-model="queryParams.taskType"
              class="full-radio-group"
            >
              <el-radio-button
                :value="1"
                label="文案生成视频"
              ></el-radio-button>
              <el-radio-button
                :value="2"
                label="图片生成视频"
              ></el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-radio-group
              v-model="queryParams.status"
              class="full-radio-group"
            >
              <el-radio-button :value="1" label="生成中"></el-radio-button>
              <el-radio-button :value="2" label="已完成"></el-radio-button>
              <el-radio-button :value="3" label="生成失败"></el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <div v-if="!userTaskList?.length" class="empty-box">
          <el-empty description="暂无数据" />
        </div>
        <WorkList v-else :list="userTaskList" @refresh="getList"></WorkList>
        <pagination
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </el-card>
    </el-card>
  </div>
</template>
<script>
import { getTaskPage } from '../../api/task';
import Video from './Video.vue';
import WorkList from './work-list.vue';

export default {
  name: 'UserTask',
  components: {
    Video,
    WorkList,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户任务表格数据
      userTaskList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户任务列表 */
    async getList() {
      this.loading = true;
      const res = await getTaskPage(this.queryParams).finally(() => {
        this.loading = false;
      });
      this.userTaskList = res.data;
      this.total = res.total;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryForm = {};
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields();
      this.handleQuery();
    },
  },
};
</script>
<style scoped lang="scss">
.subTitle {
  color: #8c8c8c;
  font-size: 16px;
}
.empty-box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
}
</style>
